import pymongo
import csv


def export_csv():
    client = pymongo.MongoClient("mongodb://localhost:27017/")
    db = client["ACM_MEMBER"]
    collection = db["OUT_TEAM_INFORMATION"]

    with open("../../../data/outer/export_file.csv", "w", newline="", encoding="utf-8") as f:
        writer = csv.writer(f)
        writer.writerow(
            ['学号', '姓名', '牛客账号', '洛谷账号', 'codeforces账号', 'atcoder账号', 'vjudge账号'])
        for information in collection.find():
            information.pop("_id")
            writer.writerow(
                [information["student_id"], information["name"], information["nowcoder_id"], information["luogu_id"],
                 information["codeforces_id"], information["atcoder_id"], information["vjudge_id"]])

    client.close()


if __name__ == '__main__':
    export_csv()